package com.example.aslongastoday.util;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;

import com.example.aslongastoday.bean.BeanFactory;
import com.example.aslongastoday.db.dao.BackLogDao;
import com.example.aslongastoday.db.dao.BackLogGroupDao;
import com.example.aslongastoday.domain.BackLogGroup;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import junit.framework.TestCase;

import java.lang.reflect.Type;
import java.util.List;
import java.util.concurrent.ExecutionException;

public class CloudUtilTest extends TestCase {
    BackLogGroupDao backLogGroupDao;
    BackLogDao dao;
    String userName = "111";

    public void init(){
        Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
        backLogGroupDao = BackLogGroupDao.getInstance(appContext);
        dao = BackLogDao.getInstance(appContext);
    }

    public void testPushBackLog() throws ExecutionException, InterruptedException {
        init();
        List<BackLogGroup> backLogGroupList = backLogGroupDao.queryAll();

        CloudUtil.PushBackLog(userName,backLogGroupList);
    }

    public void testPullBackLog() throws ExecutionException, InterruptedException {
        init();
        List<BackLogGroup> backLogGroupList = CloudUtil.PullBackLog(userName);
        System.out.println(backLogGroupList);
    }

    public void  test(){
//        init();
//        List<BackLogGroup> backLogGroupList = backLogGroupDao.queryAll();
        Gson gson = BeanFactory.makeGsonBean();
//        String s = gson.toJson(backLogGroupList);
        Type type = new TypeToken<List<BackLogGroup>>() {
        }.getType();
        String s = "";
        Object o = gson.fromJson(s, type);

        System.out.println(o);
    }
}